home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Chans / shell / tb_getprog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  2.8 KB  |  132 lines

  1. /* tb_getprog.c: get prog/shell channel entry */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Chans/shell/RCS/tb_getprog.c,v 6.0 1991/12/18 20:11:52 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Chans/shell/RCS/tb_getprog.c,v 6.0 1991/12/18 20:11:52 jpo Rel $
  9.  *
  10.  * $Log: tb_getprog.c,v $
  11.  * Revision 6.0  1991/12/18  20:11:52  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include    "util.h"
  19. #include    "table.h"
  20. #include    "prog.h"
  21.  
  22. extern char    *compress();
  23.  
  24. #define     DEFAULT_TIMEOUT    5*60    /* 5 mins */
  25.  
  26. ProgInfo *tb_getprog (key, tbl)
  27. char        *key;
  28. Table        *tbl;
  29.  
  30. {
  31.     char    buf[BUFSIZ],
  32.         *timeout_value,
  33.         *ix,*ix2;
  34.     struct passwd *pwd;
  35.     char    *cp;
  36.     ProgInfo *prog;
  37.  
  38.     PP_DBG(("tb_getprog (%s)", key));
  39.  
  40.     if (tbl == NULLTBL) {
  41.         PP_LOG(LLOG_FATAL, ("tb_getprog (no table)"));
  42.         return NULLPROG;
  43.     }
  44.  
  45.     if (tb_k2val (tbl, key, buf, TRUE) == NOTOK)
  46.         return (NULLPROG);
  47.  
  48.     /* syntax uid,timeout,cmd line */
  49.  
  50.     if ((ix = index(buf,',')) == NULLCP) {
  51.         PP_LOG(LLOG_EXCEPTIONS,
  52.                ("incorrect table syntax for entry '%s' (missing ,)",
  53.             key));
  54.         return NULLPROG;
  55.     }
  56.     *ix++ = '\0';
  57.  
  58.     prog = (ProgInfo *) smalloc (sizeof *prog);
  59.     bzero ((char *)prog, sizeof *prog);
  60.  
  61.     /* uid is either a name or a uid/gid pair */
  62.     if (isdigit (*buf) && (cp = index (buf, '/'))) {
  63.         prog -> username = NULLCP;
  64.         *cp ++ = NULL;
  65.         prog -> uid = atoi (buf);
  66.         prog -> gid = atoi (cp);
  67.         prog -> home = strdup ("/tmp");
  68.     }
  69.     else {
  70.         prog->username = strdup(buf);
  71.     
  72.         if ((pwd = getpwnam(prog->username)) == NULL) {
  73.             PP_OPER(NULLCP,
  74.                 ("tb_getprog no user '%s' with key '%s'",
  75.                  prog->username, key));
  76.             
  77.             prog_free (prog);
  78.             return NULLPROG;
  79.         }
  80.         prog -> uid = pwd -> pw_uid;
  81.         prog -> gid = pwd -> pw_gid;
  82.                 prog -> home = strdup (pwd -> pw_dir);
  83.         if (pwd -> pw_shell)
  84.             prog -> shell = strdup (pwd -> pw_shell);
  85.     }
  86.     if (prog -> shell == NULLCP)
  87.         prog -> shell = strdup ("/bin/sh");
  88.  
  89.     timeout_value  = ix;
  90.     if ((ix = index(timeout_value, ',')) == NULLCP) {
  91.         PP_LOG(LLOG_EXCEPTIONS,
  92.                ("incorrect table syntax for '%s' entry (missing ,:)",
  93.             key));
  94.         prog_free (prog);
  95.         return NULLPROG;
  96.     }
  97.     *ix++ = '\0';
  98.     (void) compress(timeout_value, timeout_value);
  99.     if ((ix2 = index(timeout_value, '|')) != NULLCP) 
  100.         *ix2++ = '\0';
  101.  
  102.     if (timeout_value[0] == '\0') 
  103.         prog -> timeout_in_secs = DEFAULT_TIMEOUT;
  104.     else
  105.         prog -> timeout_in_secs = atoi(timeout_value);
  106.     
  107.     if (ix2 != NULLCP
  108.         && lexnequ(ix2, "solo", strlen("solo")) == 0)
  109.         prog -> solo = TRUE;
  110.     else
  111.         prog -> solo = FALSE;
  112.  
  113.     prog -> cmd_line = strdup(ix);
  114.     return prog;
  115. }
  116.  
  117. void prog_free (prog)
  118. ProgInfo *prog;
  119. {
  120.     if (prog == NULLPROG)
  121.         return;
  122.     if (prog -> cmd_line)
  123.         free (prog -> cmd_line);
  124.     if (prog -> username)
  125.         free (prog -> username);
  126.     if (prog -> home)
  127.         free (prog -> home);
  128.     if (prog -> shell)
  129.         free (prog -> shell);
  130.     free ((char *)prog);
  131. }
  132.